package Func;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025-02-16
 * Time: 02:17
 */
public class ReturnFunc implements Func{
    @Override
    public void work(BookList bookList) {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入你要归还的书名");
        String name = in.nextLine();
        int curSize = bookList.getUsedSize();
        for (int i = 0; i < curSize; i++) {
            Book book = bookList.getBooks(i);
            if (book.getName().equals(name)){
                if (book.getBoolean()){
                    book.setBoolean(false);
                    System.out.println("成功归还" + "《" +name + "》");
                }else {
                    System.out.println("已经归还了图书");
                }
                return;//结束方法
            }
        }
        System.out.println("没有找到你要归还的图书");
    }
}
